package com.sfac.springCloudTest.dao;

import org.apache.ibatis.annotations.*;
import org.example.test.entity.Country;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author jzq
 * @date 2022/8/18 13:55
 */
@SuppressWarnings({"all"})
@Mapper
@Repository
public interface CountryDao {

    @Select("select * from test_country where country_id = #{countryId}")
    @Results(id = "countryResult", value = {
            @Result(column = "country_id", property="countryId"),
            @Result(column = "country_id",
                    property = "cities",
                    javaType = List.class,
                    many=@Many(select="com.sfac.springCloudTest.dao.CityDao.getCitiesByCountryId")
            )
    })
    Country getCountryByCountryId(int countryId);



    @Select("select * from test_country where country_name = #{countryName} limit 1")
    @ResultMap(value = "countryResult")
    Country getCountryByCountryName(String countryName);


}
